#include <bits/stdc++.h>
using namespace std;

map < int, int > mp, mpb;
int ans = 0, cnt = 0, n;
int last[5];
int a[200005], b[200005], c[200005], d[200005];

int read()
{
	int n = 0, d = 1;
	char c;
	while ((c = getchar()) && !isdigit(c)) {if (c == '-') d = -1;}
	if (isdigit(c)) n = (c - '0');
	while ((c = getchar()) && c <= '9' && c >= '0') {n = n * 10 + (c - '0');}
	return n * d;
}

void write(int n)
{
	if (n < 0) {n = -n; putchar('-');}
	if (n >= 10) write(n / 10);
	putchar(char(n % 10 + '0'));
}

void color()
{
    for (int i = 1; i <= n; i++)
        d[i] = c[mpb[a[i]]];
}

int work()
{
    last[1] = last[2] = 0;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (last[d[i]] == 0) last[d[i]] = i;
        else
        {
            if (a[last[d[i]]] == a[i]) ans = ans + a[i];
            last[d[i]] = i;
        }
    }
    return ans;
}

void dfs(int dep)
{
    if (dep > cnt)
    {
        color();
        ans = max(ans, work());
        return;
    }
    for (int i = 1; i <= 2; i++)
    {
        c[dep] = i;
        dfs(dep + 1);
    }
}

void solve()
{
    n = read();
    mp.clear();
    ans = 0;
    for (int i = 1; i <= n; i++)
        a[i] = read(), mp[a[i]]++;
    for (auto e : mp)
        b[++cnt] = e.first, mpb[e.first] = b[cnt];
    dfs(1);
    write(ans);
    putchar('\n');
}

int main()
{
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	int T = read();
    while (T--) solve();
	return 0;
}
